package EXEMPLE;
/*
#
Parse CSV File using StringTokenizer example.
#
This example shows how to parse comma separated file (CSV file) using
#
Java StringTokenizer and BufferedReader classes.
#
*/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.StringTokenizer;



      public class TextScannerorCSV {

      public static void main(String[] args) {

      try

{


//csv file containing data

      String strFile = "/home/depit/Desktop/lucian.txt";



//create BufferedReader to read csv file

       BufferedReader br = new BufferedReader( new FileReader(strFile));
       String strLine = "";
       StringTokenizer st = null;
       int lineNumber = 0, tokenNumber = 0;

      //read comma separated file line by line

       while( (strLine = br.readLine()) != null)
{
       lineNumber++;



//break comma separated line using ","

        st = new StringTokenizer(strLine, ",");
        while(st.hasMoreTokens())

{

//display csv values

        tokenNumber++;
        System.out.println("Line # " + lineNumber +
        ", Token # " + tokenNumber
      + ", Token : "+ st.nextToken());

}



//reset token number

          tokenNumber = 0;

}


}
          catch(Exception e)

{

          System.out.println("Exception while reading csv file: " + e);

}

}

}